<template>
  <div class="root">
    <div v-show="true" class="container">
      <img class="container-left" :src="IconPradypod" />
      <div class="container-right">
        <b class="txt-title1">Pradypod</b>
        <div>Sign in to your Account</div>
        <el-input
          v-model="username"
          class="input-username"
          placeholder="Username"
          prefix-icon="el-icon-user"
        >
        </el-input>
        <el-input
          v-model="password"
          class="input-password"
          placeholder="Password"
          prefix-icon="el-icon-lock"
        >
        </el-input>
        <b class="txt-forgot">Forgot Password?</b>
        <div class="btn-login-parent">
          <el-button
            class="btn"
            type="primary"
            round
            :loading="isLogingIn"
            @click="signinClick"
            >SIGN IN</el-button
          >
          <el-button class="btn" round @click="signupClick">SIGN UP</el-button>
        </div>
        <div class="txt-loginwith">OR LOGIN WITH</div>
        <div class="btn-login-parent">
          <el-button class="btn-circle" round
            ><b class="btn-circle-content">f</b></el-button
          >
          <el-button class="btn-circle" round
            ><img class="btn-circle-content" :src="IconGoogle"
          /></el-button>
          <el-button class="btn-circle" round
            ><b class="btn-circle-content">in</b></el-button
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import IconGoogle from "@/public/ic_google.png";
import IconPradypod from "@/public/pradypod.png";
import { ref } from "vue";
import { useRouter } from "vue-router";
import { WEBSOCKET_URL } from "@/common/constant";
import websocket from "@/service/wochatWebsocket";
const router = useRouter();
import { useUserStore } from "@/store/user";

const userStore = useUserStore();

const isLogingIn = ref(false);
const username = ref("liudehuaii18");
const password = ref("wananzhuo");

const signinClick = () => {
  console.log(username.value, password.value);
  isLogingIn.value = true;
  websocket.init(WEBSOCKET_URL, (e) => {
    console.log("websocket recv:", e);
    if (e?.msgType === "onopen") {
      userStore.login(username.value);
    }
  });
};
const signupClick = () => {
  setTimeout(() => {
    router.push("/");
  }, 2000);
};
</script>

<style scoped>
.root {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
.container {
  display: flex;
  background: white;
  height: 80vh;
  width: 80vw;
  border-radius: 10px;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 10px #666;
  flex-direction: row;
  position: absolute;
}
.container-left {
  width: 40%;
}
.container-right {
  max-width: 30vw;
  width: 50%;
  height: 60%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.txt-title1 {
  font-size: 28px;
  margin-bottom: 8px;
}
.txt-forgot {
  font-size: 14px;
}
.txt-loginwith {
  margin-top: 50px;
}
.input-username {
  width: 70%;
  margin-top: 20px;
  margin-bottom: 10px;
  border-radius: 20px !important;
}
.input-password {
  width: 70%;
  margin-bottom: 14px;
}
.btn-login-parent {
  width: 70%;
  display: flex;
  margin-top: 20px;
  justify-content: space-around;
}
.btn {
  flex: 1;
  height: 40px;
  padding: 8px 8px !important;
}
.btn-round {
  flex: 1;
}
.btn-circle {
  padding: 5px !important;
  border-radius: 20px;
  width: 40px;
  height: 40px;
}
.btn-circle-content {
  width: 18px;
  font-size: 20px;
  color: rgb(61, 112, 170);
}

@media screen and (max-width: 700px) {
  .container {
    display: flex;
    background: white;
    height: 95vh;
    width: 80vw;
    border-radius: 10px;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 10px #666;
    flex-direction: column;
  }
  .container-left {
    width: 65%;
  }
  .container-right {
    max-width: 100vw;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .input-username {
    margin-top: 20px;
    margin-bottom: 10px;
  }
  .input-password {
    margin-bottom: 14px;
  }
}
</style>
